#存放假数据，

from datetime import datetime, timedelta

def convert_coords_to_box(coords):
    """将坐标转换为中心点和宽高"""
    xmin, ymin, xmax, ymax = map(float, coords.split(','))
    x_center = (xmin + xmax) / 2
    y_center = (ymin + ymax) / 2
    width = xmax - xmin
    height = ymax - ymin
    return x_center, y_center, width, height

# 基础检测时间
base_time = datetime.now()

# 模拟检测数据
MOCK_DETECTION_DATA = [
    {
        'image_path': 'uncheck-images/00037.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.51s',
        'detections': [
            {
                'id': '001',
                'type': '坦克',
                'confidence': '0.95',
                'coords': '100,150,300,400'
            },
            {
                'id': '002',
                'type': '装甲车',
                'confidence': '0.88',
                'coords': '450,200,650,380'
            },
            {
                'id': '003',
                'type': '士兵',
                'confidence': '0.92',
                'coords': '700,300,800,450'
            },
                        {
                'id': '999',
                'type': '潜艇',
                'confidence': '0.99',
                'coords': '700,300,800,450'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00037.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.48s',
        'detections': [
            {
                'id': '001',
                'type': '装甲车',
                'confidence': '0.93',
                'coords': '120,160,320,410'
            },
            {
                'id': '002',
                'type': '坦克',
                'confidence': '0.89',
                'coords': '470,220,670,400'
            },
            {
                'id': '003',
                'type': '士兵',
                'confidence': '0.91',
                'coords': '720,320,820,470'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00070.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.52s',
        'detections': [
            {
                'id': '001',
                'type': '直升机',
                'confidence': '0.94',
                'coords': '140,170,340,420'
            },
            {
                'id': '002',
                'type': '运输车',
                'confidence': '0.87',
                'coords': '490,240,690,420'
            },
            {
                'id': '003',
                'type': '装甲车',
                'confidence': '0.90',
                'coords': '740,340,840,490'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00303.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.49s',
        'detections': [
            {
                'id': '001',
                'type': '坦克',
                'confidence': '0.96',
                'coords': '160,180,360,430'
            },
            {
                'id': '002',
                'type': '士兵',
                'confidence': '0.92',
                'coords': '510,260,710,440'
            },
            {
                'id': '003',
                'type': '直升机',
                'confidence': '0.89',
                'coords': '760,360,860,510'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00304.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.50s',
        'detections': [
            {
                'id': '001',
                'type': '运输车',
                'confidence': '0.91',
                'coords': '180,190,380,440'
            },
            {
                'id': '002',
                'type': '装甲车',
                'confidence': '0.88',
                'coords': '530,280,730,460'
            },
            {
                'id': '003',
                'type': '坦克',
                'confidence': '0.93',
                'coords': '780,380,880,530'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00415.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.47s',
        'detections': [
            {
                'id': '001',
                'type': '士兵',
                'confidence': '0.90',
                'coords': '200,200,400,450'
            },
            {
                'id': '002',
                'type': '直升机',
                'confidence': '0.95',
                'coords': '550,300,750,480'
            },
            {
                'id': '003',
                'type': '运输车',
                'confidence': '0.87',
                'coords': '800,400,900,550'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00626.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.53s',
        'detections': [
            {
                'id': '001',
                'type': '装甲车',
                'confidence': '0.92',
                'coords': '220,210,420,460'
            },
            {
                'id': '002',
                'type': '坦克',
                'confidence': '0.94',
                'coords': '570,320,770,500'
            },
            {
                'id': '003',
                'type': '士兵',
                'confidence': '0.89',
                'coords': '820,420,920,570'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00627.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.46s',
        'detections': [
            {
                'id': '001',
                'type': '直升机',
                'confidence': '0.93',
                'coords': '240,220,440,470'
            },
            {
                'id': '002',
                'type': '运输车',
                'confidence': '0.86',
                'coords': '590,340,790,520'
            },
            {
                'id': '003',
                'type': '装甲车',
                'confidence': '0.91',
                'coords': '840,440,940,590'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00628.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.54s',
        'detections': [
            {
                'id': '001',
                'type': '坦克',
                'confidence': '0.97',
                'coords': '260,230,460,480'
            },
            {
                'id': '002',
                'type': '士兵',
                'confidence': '0.90',
                'coords': '610,360,810,540'
            },
            {
                'id': '003',
                'type': '直升机',
                'confidence': '0.88',
                'coords': '860,460,960,610'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00640.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.45s',
        'detections': [
            {
                'id': '001',
                'type': '运输车',
                'confidence': '0.89',
                'coords': '280,240,480,490'
            },
            {
                'id': '002',
                'type': '装甲车',
                'confidence': '0.93',
                'coords': '630,380,830,560'
            },
            {
                'id': '003',
                'type': '坦克',
                'confidence': '0.92',
                'coords': '880,480,980,630'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00641.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.55s',
        'detections': [
            {
                'id': '001',
                'type': '士兵',
                'confidence': '0.91',
                'coords': '300,250,500,500'
            },
            {
                'id': '002',
                'type': '直升机',
                'confidence': '0.96',
                'coords': '650,400,850,580'
            },
            {
                'id': '003',
                'type': '运输车',
                'confidence': '0.85',
                'coords': '900,500,1000,650'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00642.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.44s',
        'detections': [
            {
                'id': '001',
                'type': '装甲车',
                'confidence': '0.94',
                'coords': '320,260,520,510'
            },
            {
                'id': '002',
                'type': '坦克',
                'confidence': '0.88',
                'coords': '670,420,870,600'
            },
            {
                'id': '003',
                'type': '士兵',
                'confidence': '0.90',
                'coords': '920,520,1020,670'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00645.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.56s',
        'detections': [
            {
                'id': '001',
                'type': '直升机',
                'confidence': '0.92',
                'coords': '340,270,540,520'
            },
            {
                'id': '002',
                'type': '运输车',
                'confidence': '0.87',
                'coords': '690,440,890,620'
            },
            {
                'id': '003',
                'type': '装甲车',
                'confidence': '0.93',
                'coords': '940,540,1040,690'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00656.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.43s',
        'detections': [
            {
                'id': '001',
                'type': '坦克',
                'confidence': '0.95',
                'coords': '360,280,560,530'
            },
            {
                'id': '002',
                'type': '士兵',
                'confidence': '0.89',
                'coords': '710,460,910,640'
            },
            {
                'id': '003',
                'type': '直升机',
                'confidence': '0.91',
                'coords': '960,560,1060,710'
            }
        ]
    },
    {
        'image_path': 'uncheck-images/00657.jpg',
        'detected_image_path': 'detected-images/test.jpg',
        'total_targets': 4,
        'time_used': '0.57s',
        'detections': [
            {
                'id': '001',
                'type': '运输车',
                'confidence': '0.90',
                'coords': '380,290,580,540'
            },
            {
                'id': '002',
                'type': '装甲车',
                'confidence': '0.94',
                'coords': '730,480,930,660'
            },
            {
                'id': '003',
                'type': '坦克',
                'confidence': '0.88',
                'coords': '980,580,1080,730'
            }
        ]
    },
]

# 模拟数据库数据（用于存储）
DB_MOCK_DATA = []

# 生成数据库数据
for i, detection in enumerate(MOCK_DETECTION_DATA):
    detect_time = base_time + timedelta(seconds=i*2)
    locate_time = detect_time + timedelta(seconds=0.5)
    
    for j, det in enumerate(detection['detections']):
        x_center, y_center, width, height = convert_coords_to_box(det['coords'])
        
        db_data = {
            'file_det_name': detection['detected_image_path'],  # 不需要指定media_id
            'target_class': det['type'],
            'pre_cision': float(det['confidence']),
            'detect_time': detect_time.strftime('%Y-%m-%d %H:%M:%S'),
            'locate_time': locate_time.strftime('%Y-%m-%d %H:%M:%S'),
            'x_center': x_center,
            'y_center': y_center,
            'width': width,
            'height': height
        }
        DB_MOCK_DATA.append(db_data)






